import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/address_list_controller.dart';
import '../../../../utils/screenAdapter.dart';

class AddressListView extends GetView<AddressListController> {
  const AddressListView({super.key});
  @override
  Widget build(BuildContext context) {
    Widget _addressItem() {
      return Container(
        decoration: BoxDecoration(
          border: Border(bottom: BorderSide(color: Colors.black12)),
        ),
        child: ListTile(
          leading: const Icon(Icons.check, color: Colors.orange),
          title: Padding(
            padding: EdgeInsets.only(left: ScreenAdapter.width(50)),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("北京市 东城区", style: TextStyle(color: Colors.black54)),
                Text("西二旗 百度大厦", style: TextStyle(fontWeight: FontWeight.bold)),
                Text(
                  "张三 152016391234",
                  style: TextStyle(color: Colors.black54),
                ),
              ],
            ),
          ),
          trailing: const Icon(Icons.edit, color: Colors.blue),
        ),
      );
    }

    Widget _pageBody() {
      return ListView(
        padding: EdgeInsets.only(
          left: ScreenAdapter.width(20),
          right: ScreenAdapter.width(20),
          bottom: ScreenAdapter.height(132),
        ),
        children: [
          _addressItem(),
          _addressItem(),
          _addressItem(),
          _addressItem(),
        ],
      );
    }

    Widget _bottomBar() {
      return Positioned(
        bottom: 0,
        left: 0,
        right: 0,
        child: Container(
          color: Colors.white,
          padding: EdgeInsets.only(
            left: ScreenAdapter.width(20),
            right: ScreenAdapter.width(20),
          ),
          child: ElevatedButton(
            style: ButtonStyle(
              padding: WidgetStateProperty.all(
                EdgeInsets.symmetric(
                  vertical: ScreenAdapter.height(ScreenAdapter.height(80)),
                ), // 上下和左右两边对称设置内边距
              ),
              backgroundColor: WidgetStateProperty.all(Colors.orange),
              foregroundColor: WidgetStateProperty.all(Colors.white),
            ),
            onPressed: () {
              print("新增收货地址");
              Get.toNamed("/address-add");
            },
            child: Text("新增收货地址"),
          ),
        ),
      );
    }

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(title: const Text('收货地址')),
      body: Stack(children: [_pageBody(), _bottomBar()]),
    );
  }
}
